package com.egao.common.publicly.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.egao.common.core.web.PageParam;
import com.egao.common.module.cms.entity.Official;
import com.egao.common.publicly.entity.PubliclyCareerVO;
import com.egao.common.publicly.entity.OfficialVO;
import com.egao.common.publicly.mapper.PubliclyOfficialMapper;
import com.egao.common.publicly.service.PubliclyOfficialService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 公务员管理实现类
 *
 * @author pyx
 */
@Service
public class PubliclyOfficialServiceImpl extends ServiceImpl<PubliclyOfficialMapper, Official> implements PubliclyOfficialService {
    @Override
    public List<OfficialVO> listPage(PageParam<PubliclyCareerVO> pageParam) {
        if (pageParam.getInt("id") == null) {
            return new ArrayList<>();
        }
        pageParam.put("type", 1);

        return baseMapper.listPage(pageParam);
    }

    @Override
    public List<OfficialVO> crawlerList() {
        return baseMapper.crawlerList();
    }

    @Override
    public Official getId(Integer id) {
        Official official = baseMapper.selectById(id);

        if (official == null) {
            return new Official();
        }

        //更新公考资讯点击量
        if (official.getHits() == null) {
            official.setHits(0);
        }
        official.setHits(official.getHits() + 1);
        baseMapper.updateById(official);

        return official;
    }

    @Override
    public Integer allHists(HashMap<String, String> createTimeMap) {
        return baseMapper.allHists(createTimeMap);
    }
}
